﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="alunosGrupo.aspx.cs" Inherits="sistemaAcademicoFinanceiroEscolas.DynamicData.CustomPages.grupos.alunosGrupo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Realizar Matrícula</title>
    <link href="Site2.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .style1
        {
            font-family: Verdana, Arial, Helvetica, sans-serif;
            font-size: 12px;
            font-style: normal;
            color: #000000;
            text-decoration: none;
            width: 83%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="lblValidacao" runat="server" ForeColor="Red" CssClass="style1"></asp:Label>
    <br />
    <table width="100%" border="0">
        <tr>
            <td width="2%">
                <img src="../images/setadireita.gif" width="16" height="14" />
            </td>
            <td width="81%" class="style1">
                Grupo
            </td>
            <td width="17%">
                <asp:Label ID="lblDescricaoGrupo" runat="server" CssClass="style1" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <img src="../images/linhaDivPops.gif" width="400" height="8" />
            </td>
        </tr>
        <tr>
            <td width="2%">
                <img src="../images/setadireita.gif" width="16" height="14" />
            </td>
            <td class="style1">
                Alunos
            </td>
            <td width="17%">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <img src="../images/linhaDivPops.gif" width="400" height="8" />
            </td>
        </tr>
        <% 
          
            //loop nos Alunos da escola

            string sqlAlunos = "select codigoAluno, nomeAluno from Aluno order by nomeAluno";

            System.Data.SqlClient.SqlConnection sqlc = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
            sqlc.Open();



            System.Data.SqlClient.SqlCommand cmdAluno = new System.Data.SqlClient.SqlCommand(sqlAlunos, sqlc);
            System.Data.SqlClient.SqlDataReader myReaderAluno = cmdAluno.ExecuteReader();

            while (myReaderAluno.Read())
            {

                System.Data.SqlClient.SqlConnection sqlc2 = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                sqlc2.Open();

                CheckBox cb = new CheckBox();
                cb.ID = myReaderAluno["codigoAluno"].ToString();
                cb.Text = myReaderAluno["nomeAluno"].ToString();

                //verificar se o Aluno já está cadastrado nesta Grupo
                //em caso positivo checar    

                string sqlAlunoGrupo = "select * from alunoGrupo where codigoAluno=" + myReaderAluno["codigoAluno"].ToString() + " and codigoGrupo=" + Request["codigoGrupo"].ToString();

                System.Data.SqlClient.SqlCommand cmdAlunoGrupo = new System.Data.SqlClient.SqlCommand(sqlAlunoGrupo, sqlc2);
                System.Data.SqlClient.SqlDataReader myReaderAlunoGrupo = cmdAlunoGrupo.ExecuteReader();  
          
        %>
        <tr>
            <td width="2%">
                <img src="../images/setadireita.gif" width="16" height="14" />
            </td>
            <td class="style1">
                <%Response.Write(myReaderAluno["nomeAluno"].ToString()); %>
            </td>
            <td width="17%">
                <%if (myReaderAlunoGrupo.HasRows)
                  {
                %>
                <input type="checkbox" name="<%Response.Write(myReaderAluno["codigoAluno"].ToString()); %>"
                    checked />
                <%
                    }
                  else
                  { 
                %>
                <input type="checkbox" name="<%Response.Write(myReaderAluno["codigoAluno"].ToString()); %>" />
                <% 
                    }
                %>
            </td>
        </tr>
        <%
            sqlc2.Close();
            }

            myReaderAluno.Close();
            cmdAluno.Dispose();
            sqlc.Close();

            myReaderAluno.Close();
            cmdAluno.Dispose();
      
          
        %>
        <tr>
            <td colspan="3">
                <img src="../images/linhaDivPops.gif" width="400" height="8" />
            </td>
        </tr>
    </table>
    <asp:Panel ID="Panel1" runat="server">
        <asp:HiddenField ID="codigoAluno" runat="server" />
    </asp:Panel>
    <p>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Definir" />
    </p>
    <div>
    </div>
    <input type="hidden" name="codigoGrupo" value="<%Response.Write(Request["codigoGrupo"].ToString()); %>" />
    </form>
</body>
</html>
